#ifndef SWANLINK_FINANCE_CARDSENDER_INTERFACES_INNERKITS_NATIVE_INCLUDE_CASHDEVICE_DEF_H
#define SWANLINK_FINANCE_CARDSENDER_INTERFACES_INNERKITS_NATIVE_INCLUDE_CASHDEVICE_DEF_H

/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http:   //  www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <string>
#include <unistd.h>

namespace SwanLink {
namespace Finance {
#define MAX_DEV_NAME_LEN 64
#define MAX_INFO_LEN 256
#define MAX_DEV_NUM  8

enum ACCESS_MODE {
    AM_USB = 0,
    AM_SERIAL,
};

struct Transport {
    ACCESS_MODE mode;
    char        dev[MAX_DEV_NAME_LEN];
    int32_t     timeout;
    int32_t     size;
};

//  USB的通讯参数定义
struct UsbTransport: Transport {
    int         bus_num;
    int         dev_num;
};

//  串口的通讯参数定义：
struct SerialTransport: Transport {
    int         baudrate;
    uint8_t     databit;
    uint8_t     stopbit;
    uint8_t     parity;
};

struct DevAccess {
    char        name[MAX_DEV_NAME_LEN];           // 设备名称
    char        desc[MAX_INFO_LEN];          //  应包含设备型号、适配信息、设备结点、版本号等
    Transport   transport;     //  通讯参数
};

// 设备类型ID
enum CASH_DEVICE_ID {
    CASH_DEVICE_FIRST = 0,
    CASH_DEVICE_KEYBOARD = 0x01,    // 密码键盘
    CASH_DEVICE_PRINTER = 0x02,     //  凭条打印机
    CASH_DEVICE_MAKECARD = 0x03,    //  制卡机
    CASH_DEVICE_CARDSENDER = 0x04,  //  发卡机

    //  添加到上方
    CASH_DEVICE_MAX
};

#define   CASH_STATUS_FIRST(ID)  (-(10000+(ID)*100))

// 状态码
#define SUCCESS                     0         // 成功
#define ERROR                       -1       // 失败
#define CANCEL                      -2       // 取消
#define TIMEOUT                     -3         // 超时
#define HANDLE_INVALID              -4         // 句柄无效
#define NOT_INIT                    -5       // 未初始化

#define ERR_DEVICE_NOT_OPEN        -101     // 设备未打开
#define ERR_DEVICE_NOT_SUPPORT     -102     // 设备不支持
#define ERR_DEVICE_OPEN_ALREADY    -103     // 设备已打开
#define ERR_DEVICE_BUSY            -104     // 设备忙
#define ERR_DEVICE_NOT_EXIST       -105     // 设备不存在
#define ERR_DEVICE_OPEN_FAILED     -106     // 设备打开失败
#define ERR_DEVICE_PERMISSION_DENY -111      // 权限问题
#define ERR_DEVICE_NO_DEVBUS       -112      // 没有设备节点
#define ERR_DEVICE_DRIVER_ERROR    -113      // 驱动内核错误
#define ERR_DEVICE_DISCONNECT      -114     // 设备断开连接

#define ERR_PLUGIN_UNLOADED        -201     // 插件未加载
#define ERR_PLUGIN_NOT_EXIST       -202     // 插件不存在
#define ERR_PLUGIN_LOAD_FAILED     -203     // 插件加载失败
#define ERR_PLUGIN_PATH_UNFIND     -204     // 插件路径错误
#define ERR_TRANS_NOT_SUPPORT      -301     // 通讯方式不支持
#define ERR_TRANS_PORT_TACKUP      -302     // 通信端口被占用
#define ERR_TRANS_PARAM_ERROR      -303     // 通信参数错误
#define ERR_TRANS_PROC_ERROR       -304     // 通信过程异常
#define ERR_TRANS_PROTO_ERROR      -305      // 通信协议错误
#define ERR_TRANS_SEND_FAILED            -311
#define ERR_TRANS_SEND_UNFINISHED        -312
#define ERR_TRANS_RECV_FAILED            -321
#define ERR_TRANS_RECV_UNFINISHED        -322

#define ERR_NAPI_PARAM_TYPE_ERROR    -401     // NAPI 参数类型错误
#define ERR_NAPI_PARAM_NUMBER_WRONG    -402     // NAPI参数个数错误
#define ERR_NAPI_PARAM_INVALID        -403         // NAPI参数无效
#define ERR_CONFIG_LOAD_FAILED  -501     // 配置文件加载失败
#define ERR_CONFIG_NOT_FIND     -502     // 配置信息没找到
}  // namespace Finance
}  // namespace SwanLink
#endif  // SWANLINK_FINANCE_CARDSENDER_INTERFACES_INNERKITS_NATIVE_INCLUDE_CASHDEVICE_DEF_H
